﻿//----------------------------------------------------------------------------------------------------------------------
// <copyright file="TaskToolbarControl.xaml.cs" company="Keith B. Rimington">
//
//   Copyright (c) 2011 Keith B. Rimington
//
//   Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
//     documentation files (the "Software"), to deal in the Software without restriction, including without limitation
//     the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
//     to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
//   The above copyright notice and this permission notice shall be included in all copies or substantial portions of
//     the Software.
//
//   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
//     THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
//     CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
//     DEALINGS IN THE SOFTWARE.
//
// </copyright>
//----------------------------------------------------------------------------------------------------------------------

namespace Noc.Pomodoro.Controls
{
    using System;
    using System.Windows;
    using System.Windows.Controls;
    using Noc.Pomodoro.Core;
    using Noc.Pomodoro.ViewModels;

    /// <summary>
    /// Interaction logic for TaskToolbarControl.xaml
    /// </summary>
    public partial class TaskToolbarControl : UserControl
    {
        /// <summary>
        /// Backing store for the TaskOperation event.
        /// </summary>
        public static readonly RoutedEvent TaskOperationEvent = EventManager.RegisterRoutedEvent("TaskOperation", RoutingStrategy.Bubble, typeof(EventHandler<TaskEventArgs>), typeof(TaskToolbarControl));

        /// <summary>
        /// Backing store for the Task property.
        /// </summary>
        public static readonly DependencyProperty TaskProperty = DependencyProperty.Register("Task", typeof(TaskViewModel), typeof(TaskToolbarControl));

        /// <summary>
        /// Initializes a new instance of the <see cref="TaskToolbarControl"/> class.
        /// </summary>
        public TaskToolbarControl()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Occurs when an operation is invoked on a task.
        /// </summary>
        public event EventHandler<TaskEventArgs> TaskOperation
        {
            add { AddHandler(TaskOperationEvent, value); }
            remove { RemoveHandler(TaskOperationEvent, value); }
        }

        /// <summary>
        /// Gets or sets the task on which to operate.
        /// </summary>
        /// <value>
        /// The task on which to operate.
        /// </value>
        public TaskViewModel Task
        {
            get { return (TaskViewModel)GetValue(TaskProperty); }
            set { SetValue(TaskProperty, value); }
        }

        /// <summary>
        /// Called when the play button is clicked, and forwards the event to TaskOperation listeners.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void OnPlayButtonClicked(object sender, RoutedEventArgs e)
        {
            RaiseEvent(new TaskEventArgs(TaskOperationEvent) { Task = this.Task, Operation = TaskOp.StartPomodoro });
        }

        /// <summary>
        /// Called when the internal enterrupt button is clicked, and forwards the event to TaskOperation listeners.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void OnInternalButtonClicked(object sender, RoutedEventArgs e)
        {
            RaiseEvent(new TaskEventArgs(TaskOperationEvent) { Task = this.Task, Operation = TaskOp.InterruptPomodoroInt });
        }

        /// <summary>
        /// Called when the external interrupt button is clicked, and forwards the event to TaskOperation listeners.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void OnExternalButtonClicked(object sender, RoutedEventArgs e)
        {
            RaiseEvent(new TaskEventArgs(TaskOperationEvent) { Task = this.Task, Operation = TaskOp.InterruptPomodoroExt });
        }

        /// <summary>
        /// Called when the void button is clicked, and forwards the event to TaskOperation listeners.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void OnVoidButtonClicked(object sender, RoutedEventArgs e)
        {
            RaiseEvent(new TaskEventArgs(TaskOperationEvent) { Task = this.Task, Operation = TaskOp.VoidPomodoro });
        }
    }
}